<?php
	defined( '_JEXEC' ) or die( 'Restricted access' );
	jimport('joomla.application.component.view');
	
	jimport('joomla.file.path');
	
	class ActinMapViewControlPanel extends JView
	{
		var $_option = null;
		
		function display($tpl = null)
		{
			$modelEvent=&$this->getModel();
			//print_r(JFactory::getUser()->id); //coge 0 deberia de ir dentro de la funcion.
			//Entre parentesis JFactory::getUser()->id
			$zerrendaOsoa=&$modelEvent->getUserEvents(JFactory::getUser()->id);
			$categories=$modelEvent->getEventCategories();
			$this->assignRef('categories', $categories);
		    $this->assignRef('events',$zerrendaOsoa);
			$this->assignRef('option', JRequest::getCmd('option'));
			$this->addCSS();
			$this->addJavascripts();
			
			parent::display($tpl);
		}
		
		private function addCSS(){
			$option=JRequest::getCmd('option');
			
			$document=&JFactory::getDocument();
			$document->addStyleSheet('components/'.$option.'/css/sunny/jquery-ui-1.8.11.custom.css');
			$document->addStyleSheet('components/'.$option.'/css/actinmap.css');
		}
		
		private function addJavascripts(){
			$option=JRequest::getCmd('option');
			
			$document=&JFactory::getDocument();
			$document->addScript('http://maps.google.com/maps/api/js?sensor=false');
			$document->addScript('components/'.$option.'/js/jquery-1.5.1.min.js');
			$document->addScript('components/'.$option.'/js/jquery-ui-1.8.11.custom.min.js');
			$id=JFactory::getUser()->id;
			$js=null;
			if($id==0){
				$js='var idUsuario=null;';
			}
			else{
				$js='var idUsuario='.$id.';';
			}
			$document->addScriptDeclaration($js);
			$document->addScript('components/'.$option.'/js/eventsMap.js');
			$document->addScript('components/'.$option.'/js/eventsControl.js');
		}
		
		public function paintMapPanel(){
			include JPath::find($this->_path['template'],'mapPanel.php');
		}
		
		public function paintFormEditPanel(){
			include JPath::find($this->_path['template'],'formEditPanel.php');
		}
		
		public function paintEventPanel($event){
			$this->assignRef('event',$event);
			include JPath::find($this->_path['template'],'eventPanel.php');
		}
		
	}
?>